<?php

$kthandle=@opendir('./');
while ($ktfile = @readdir($kthandle)) {
	if ( (!ereg("[.]",$ktfile)) AND (ereg("install",$ktfile)) ) {
		Header("Location:$ktfile/install.php");
		exit;
	}
}
@closedir($kthandle);
if (!file_exists("mainfile.php")) { exit(); }
define('NV_SYSTEM', true);
@require_once("mainfile.php");
$module = 1;

if (isset($name) && $name == $_REQUEST['name']) {
	$name = addslashes(trim($name));
	$modstring = strtolower($_SERVER['QUERY_STRING']);
	if (stripos_clone($name, "..") OR ((stripos_clone($modstring,"&file=nickpage") || stripos_clone($modstring,"&user=")) AND ($name=="Private_Messages" OR $name=="Forums" OR $name=="Members_List"))) {
		header("Location: index.php");
		exit();
	}
	global $nukeuser;
	if (defined('IS_USER')) {
		$nukeuser = base64_decode($user);
		$nukeuser = addslashes($nukeuser);
	} else {
		$nukeuser = "";
	}

	list($module_title, $mod_active, $view, $adm_mod) = $db->sql_fetchrow($db->sql_query("SELECT custom_title, active, view, admins FROM ".$prefix."_modules WHERE title='".addslashes($name)."'"));
	$mod_active = intval($mod_active);
	$view = intval($view);
	$adm_mod = explode(",", $adm_mod);
	if(defined('IS_ADMIN') AND ($adm_super==1 || (in_array($adm_name,$adm_mod) AND $adm_name!=""))) {
		define('IS_ADMMOD', TRUE);
	}
	if (($mod_active == 1) OR ($mod_active == 0 AND defined('IS_ADMMOD'))) {
		if (!isset($mop) OR $mop != $_REQUEST['mop']) $mop="modload";
		if (!isset($file) OR $file != $_REQUEST['file']) $file="index";
		if (stripos_clone($file,"..") OR stripos_clone($mop,"..")) die("You are so cool...");
		$modpath = "";
		if ($view == 0) {
			$modpath .= "modules/".$name."/".$file.".php";
			if (file_exists($modpath)) {
				include($modpath);
			} else {
				include("header.php");
				OpenTable();
				echo "<br><center>Sorry, such file doesn't exist...</center><br>";
				CloseTable();
				include("footer.php");
				die();
			}
		} elseif ($view == 1 AND defined('IS_USER') || defined('IS_ADMMOD')) {
			$modpath .= "modules/".$name."/".$file.".php";
			if (file_exists($modpath)) {
				include($modpath);
			} else {
				include("header.php");
				OpenTable();
				echo "<br><center>Sorry, such file doesn't exist...</center><br>";
				CloseTable();
				include("footer.php");
				die();
			}
		} elseif ($view == 1 AND !defined('IS_USER') || !defined('IS_ADMMOD')) {
			$pagetitle = "- "._ACCESSDENIED."";
			include("header.php");
			title("$sitename: "._ACCESSDENIED."");
			OpenTable();
			echo "<center><b>"._RESTRICTEDAREA."</b><br><br>"._MODULEUSERS.""._GOBACK."";
			CloseTable();
			include("footer.php");
			die();
		} elseif ($view == 2 AND defined('IS_ADMMOD')) {
			$modpath .= "modules/".$name."/".$file.".php";
			if (file_exists($modpath)) {
				include($modpath);
			} else {
				include("header.php");
				OpenTable();
				echo "<br><center>Sorry, such file doesn't exist...</center><br>";
				CloseTable();
				include("footer.php");
				die();
			}
		} elseif ($view == 2 AND !defined('IS_ADMMOD')) {
			$pagetitle = "- "._ACCESSDENIED."";
			include("header.php");
			title("$sitename: "._ACCESSDENIED."");
			OpenTable();
			echo "<center><b>"._RESTRICTEDAREA."</b><br><br>"._MODULESADMINS.""._GOBACK."";
			CloseTable();
			include("footer.php");
			die();
		}
	} else {
		include("header.php");
		OpenTable();
		echo "<center>"._MODULENOTACTIVE."<br><br>"._GOBACK."</center>";
		CloseTable();
		include("footer.php");
	}
} else {
	header("Location: index.php");
	exit;
}

?>
